﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AIOptimization.Algorithms;

namespace AIOptimization
{
    class BacterialTest : BacterialForagingOptimization
    {
        public BacterialTest()
        {
            this.NewBestResult += new NewBestResultEvent(BacterialTest_NewBestResult);
            SetParameter(100, 20, 5, 0.25, 0.05, 8, 4, -5.12, 5.12);
            Execute();
        }

        void BacterialTest_NewBestResult(object o, Algorithms.Repositories.BestBacteriumResult e)
        {
            Console.WriteLine("New Best Cost");
            Console.WriteLine(string.Format("Position: {3}, Time:{1}, Bacteria: {2}, Cost:{0}\n", e.Cost.ToString("F5"), e.Time, e.Bacteria, ShowVector(e.Position)));
        }

        public override double ObjectiveFunction(double[] x)
        {
            //f(x,y) = (x^2 - 10*cos(2*PI*x)) + (y^2 - 10*cos(2*PI*y)) + 20 
            return (Math.Pow(x[0], 2) - 10 * Math.Cos(2 * Math.PI * x[0])) + (Math.Pow(x[1], 2) - 10 * Math.Cos(2 * Math.PI * x[1])) + 20;
        }
    }
}
